#include "StdAfx.h"

LightDesc::LightDesc()
{
	Color=Vec3(1,1,1);
	Type=SpotLight;
	Dir=Vec3(0,0,-1);
	bOrbit=false;;
	Focus=Vec3(0,0,0);
	OrbitVel=Vec3(0,0,0);
}
Light::Light(LightDesc &desc):Actor(desc)
{
	Dir=desc.Dir;
	Type=desc.Type;
	if(!desc.TextureName.empty())
		Texture=_RESC(desc.TextureName);
	Color=desc.Color;
	bOrbit=desc.bOrbit;
	Focus=desc.Focus;
	OrbitVel=desc.OrbitVel;
}
Light::~Light(void)
{
}
sptr<Camera> Light::GetCamera()
{
	CameraDesc cdesc;
	cdesc.Pos=Pos;
	cdesc.At=Pos+Dir;
	cdesc.FOV=90;
	sptr<Camera> camera=sptr<Camera>(new Camera(cdesc));
	return camera;
}
void Light::Update(double dt)
{
	if(bOrbit)
	{
		Vec3 orbit=Pos-Focus;
		double distance=orbit.magnitude();
		orbit.normalize();
		Vec3 vd=orbit.cross(OrbitVel);
		Pos+=vd*dt;
		Dir=Focus-Pos;
	}
}
void Light::React(sptr<Actor>)
{
}
